package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.model.Department;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface DepartmentMapper extends BaseMapper<Department> {

    @Select("SELECT name FROM department WHERE id = #{departmentId}")
    String getNameById(int departmentId);

    @Select("SELECT * FROM department")
    List<Department> getDepartmentList();

    @Select("SELECT * FROM department WHERE id = #{id}")
    Department getDepartmentById(int id);

    @Select("SELECT * FROM department ORDER BY id LIMIT 5")
    List<Department> getTop5Departments();

    @Select("SELECT * FROM department")
    List<Department> getDepartments();

    @Delete("DELETE FROM department WHERE id = #{id}")
    void deleteDepartmentById(int id);

    @Update("UPDATE department SET name = #{name}, parent_id = #{parentId}, manager_id = #{managerId}, create_time = #{createTime}, update_time = #{updateTime} WHERE id = #{id}")
    void updateDepartment(Department department);

    @Insert("INSERT INTO department(name, parent_id, manager_id, create_time, update_time) VALUES(#{name}, #{parentId}, #{managerId}, #{createTime}, #{updateTime})")
    void insertDepartment(Department department);
}
